package o;

import android.os.Build.VERSION;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.huawei.appgallery.packagemanager.api.bean.ManagerTask;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

public class cow extends ArrayList<ManagerTask> {
    private int ˊ = 0;
    private Map<String, List<ManagerTask>> ˋ = new ConcurrentHashMap();
    private int ˎ = 4096;
    private int ˏ = 2048;

    public /* synthetic */ boolean add(@NonNull Object obj) {
        return ˎ((ManagerTask) obj);
    }

    public /* synthetic */ Object remove(int i) {
        return ˋ(i);
    }

    public boolean ˎ(@NonNull ManagerTask managerTask) {
        ॱ(managerTask);
        return super.add(managerTask);
    }

    public boolean addAll(@NonNull Collection<? extends ManagerTask> collection) {
        for (ManagerTask ॱ : collection) {
            ॱ(ॱ);
        }
        return super.addAll(collection);
    }

    private void ॱ(ManagerTask managerTask) {
        List list = (List) this.ˋ.get(managerTask.packageName);
        if (list == null) {
            list = new CopyOnWriteArrayList();
            this.ˋ.put(managerTask.packageName, list);
        }
        if (!list.contains(managerTask)) {
            list.add(managerTask);
        }
        ˏ(managerTask);
    }

    public ManagerTask ˋ(int i) {
        ManagerTask managerTask = (ManagerTask) super.remove(i);
        if (managerTask != null) {
            ˊ(managerTask);
        }
        ˊ();
        return managerTask;
    }

    public boolean remove(@NonNull Object obj) {
        if (obj instanceof ManagerTask) {
            ˊ((ManagerTask) obj);
        }
        boolean remove = super.remove(obj);
        ˊ();
        return remove;
    }

    private void ˊ(@NonNull ManagerTask managerTask) {
        List list = (List) this.ˋ.get(managerTask.packageName);
        if (list != null) {
            list.remove(managerTask);
            if (list.isEmpty()) {
                this.ˋ.remove(managerTask.packageName);
            }
        }
    }

    public boolean removeAll(@NonNull Collection<?> collection) {
        boolean removeAll = super.removeAll(collection);
        ˊ();
        return removeAll;
    }

    private void ˊ() {
        if (isEmpty()) {
            this.ˏ = 0;
            this.ˊ = 0;
            this.ˎ = 0;
        }
    }

    private void ˏ(@NonNull ManagerTask managerTask) {
        int i;
        if (managerTask.taskPriority == coc.NORMAL) {
            i = this.ˏ + 1;
            this.ˏ = i;
            managerTask.taskIndex = i;
        } else if (managerTask.taskPriority == coc.IMPORTANCE) {
            i = this.ˊ + 1;
            this.ˊ = i;
            managerTask.taskIndex = i;
        } else {
            i = this.ˎ + 1;
            this.ˎ = i;
            managerTask.taskIndex = i;
        }
    }

    public ManagerTask ˊ(@NonNull String str, long j) {
        List<ManagerTask> list = (List) this.ˋ.get(str);
        if (list != null) {
            for (ManagerTask managerTask : list) {
                if (str.equals(managerTask.packageName) && j == managerTask.taskId) {
                    return managerTask;
                }
            }
        }
        return null;
    }

    @Nullable
    public List<ManagerTask> ˎ(String str) {
        List<ManagerTask> list = (List) this.ˋ.get(str);
        if (list == null) {
            return null;
        }
        return VERSION.SDK_INT <= 25 ? new ArrayList(list) : list;
    }
}
